#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>


#include "Array.h"

int InitArray(Array &A,int dim)
{
	int i;
	va_list ap;
	if (dim<1||dim>MAX_ARRAY_DIM)
	{
		return 0;
	}
	A.dim=dim;
	A.bounds=(int *)malloc(dim*sizeof(int));
	if (!A.bounds)
	{
		exit(-2);
	}
	int elemtotal=1;
	va_start(ap,dim);
	for (i=0;i<dim;++i)
	{
		A.bounds[i]=va_arg(ap,int);
		if (A.bounds[i]<0)
		{
			return 0;
		}
		elemtotal*=A.bounds[i];
	}
	va_end(ap);
	A.base=(int *)malloc(elemtotal*sizeof(int));
	if (!A.base)	
	{
		exit(-2);
	}
	A.constants=(int *)malloc(dim*sizeof(int));
	if (!A.constants)
	{
		exit(-2);
	}
	A.constants[dim]=1;
	for (i=dim-2;i>=0;--i)
	{
		A.constants[i]=A.bounds[i+1]*A.constants[i+1];
	}
	return 1;
}

void main()
{

}